package org.example.movies.dao.impl;

import org.example.movies.dao.FilmDao;
import org.example.movies.pojo.TFilm;
import org.example.movies.utils.IndexData;
import org.example.movies.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * @version 1.0
 * @Author: xxf
 * @CreateDate: 2020/10/16 16:03
 */
public class FilmDaoImpl implements FilmDao {

    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public List<TFilm> selectAllFilm() {
        String sql = "select id, actor, cate_log_name, cate_log_id, evaluation, image," +
                " isUse, loc_name, loc_id, name, on_decade, plot, resolution, " +
                "status, sub_class_name, sub_class_id, type_name, type_id, update_time, " +
                "is_vip from t_film order by evaluation desc ";

        List<TFilm> list = template.query(sql, new BeanPropertyRowMapper<TFilm>(TFilm.class));

        return list;
    }

    @Override
    public List<TFilm> selectMoives() {
        return null;
    }


    @Override
    public TFilm selectFilmById(String id) {
        String sql = "SELECT id, actor, cate_log_name, cate_log_id," +
                " evaluation, image, isUse, loc_name, loc_id, " +
                "name, on_decade, plot, resolution, status, " +
                "sub_class_name, sub_class_id, type_name, " +
                "type_id FROM t_film  where id=?";
        TFilm tFilm = template.queryForObject(sql, new BeanPropertyRowMapper<TFilm>(TFilm.class), id);
        return tFilm;
    }

    @Override
    public List<TFilm> selectTFilm(String id) {
        String sql = "select id, actor, cate_log_name, cate_log_id, evaluation, image," +
                " isUse, loc_name, loc_id, name, on_decade, plot, resolution, " +
                "status, sub_class_name, sub_class_id, type_name, type_id, update_time, " +
                "is_vip from t_film  where cate_log_id=?";

        List<TFilm> list = template.query(sql, new BeanPropertyRowMapper<TFilm>(TFilm.class),id);

        return list;
    }


}
